//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media.Media3D;
using OpenLS.Chart.UI.Internals;

namespace OpenLS.Chart.UI
{
    internal abstract class CameraXYZConverter : IMultiValueConverter
    {
        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            Camera3D2DProjector camera = (Camera3D2DProjector) values[0];
            if (camera == null)
                return GetValue(new Point(0, 0));
            double x = System.Convert.ToDouble(values[1]);
            double y = System.Convert.ToDouble(values[2]);
            double z = System.Convert.ToDouble(values[3]);
            Point3D input = new Point3D(x, y, z);
            Point pt = camera.Point3DToPoint2D(input);
            return GetValue(pt);
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion

        protected abstract double GetValue(Point pt);
    }
}